package com.xyebank.ledger.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Md5Util {
	public static String fileMd5Code(File file) {

		FileInputStream fins = null;
		String md5val = null;
		try {
			fins = new FileInputStream(file);
			byte[] data = new byte[fins.available()];
			fins.read(data);
			byte[] md5byte = Coder.encryptMD5(data);
			md5val = ByteHexSringUtils.bytesToHexString(md5byte);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (fins != null) {
					fins.close();
				}
			} catch (IOException e) {

			}
		}

		// String md5base64 = Coder.encryptBASE64(md5byte);

		return md5val;
	}
}
